package com.liuyang.second.concurrency.chapter5;

public class Gate {
    private int counter = 0;
    private String name = "Nobody";
    private String address = "Nowhere";

    private final Object object = new Object();

    public Gate() {
    }

    public void pass(String name, String address) {
        synchronized (object){
            this.counter++;
            this.name = name;
            this.address = address;
        }
        verify();
    }

    private void verify(){
        if(this.name.charAt(0)!=this.address.charAt(0)){
            System.out.println("*****BROKEN******"+toString());
        }
    }

    public String toString(){
        return "No."+counter+":"+name+","+address;
    }


}
